package com.weipai.education.dao.impl;

import com.weipai.education.dao.InventoryDao;
import com.weipai.education.mapper.*;
import com.weipai.education.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/13 17:26
 */
@Repository
public class InventoryDaoImpl implements InventoryDao {

    @Autowired
    private InventoryMapper inventoryMapper;
    @Autowired
    private InventoryDetailMapper inventoryDetailMapper;
    @Autowired
    private InventoryOutMapper inventoryOutMapper;
    @Autowired
    private InventoryOutDetailMapper inventoryOutDetailMapper;
    @Autowired
    private InventoryInMapper inventoryInMapper;
    @Autowired
    private InventoryInDetailMapper inventoryInDetailMapper;

    @Override
    public List<Map<String, Object>> list(Integer start, Integer size, String spuNumber, String key, String userId) {
        return inventoryMapper.list(start, size, spuNumber, key, userId);
    }

    @Override
    public Integer listAmount(String spuNumber, String key, String userId) {
        return inventoryMapper.listAmount(spuNumber, key, userId);
    }

    @Override
    public InventoryDetail getInventoryDetail(String userId, String productId, String goodsBarCode) {
        return inventoryDetailMapper.getInventoryDetail(userId, productId, goodsBarCode);
    }

    @Override
    public Inventory getInventory(String userId, String productId) {
        return inventoryMapper.getInventory(userId, productId);
    }

    @Override
    public int updateByPrimaryKeySelective(Inventory inventory) {
        return inventoryMapper.updateByPrimaryKeySelective(inventory);
    }

    @Override
    public void batchDeleteInventoryDetailById(List<Integer> inventoryDetailId) {
        for (Integer id : inventoryDetailId){
            inventoryDetailMapper.deleteByPrimaryKey(id);
        }
    }
    @Override
    public List<Map<String,Integer>> selectDetailPeoduct(Integer productId,Integer userId,Integer totalNumber) {
       return inventoryDetailMapper.selectDetailPeoduct(productId,userId,totalNumber);

    }

    @Override
    public int saveInventoryIn(InventoryIn in) {
        return inventoryInMapper.insert(in);
    }

    @Override
    public int saveInventoryInDetail(InventoryInDetail inventoryInDetail) {
        return inventoryInDetailMapper.insert(inventoryInDetail);
    }

    @Override
    public int saveInventoryInDetailByNobarcode(InventoryInDetail inventoryInDetail) {
        return inventoryInDetailMapper.insertNobarcode(inventoryInDetail);
    }

    @Override
    public int saveInventoryOut(InventoryOut out) {
        return inventoryOutMapper.insert(out);
    }

    @Override
    public int saveInventoryOutDetail(InventoryOutDetail inventoryOutDetail) {
        return inventoryOutDetailMapper.insert(inventoryOutDetail);
    }

    @Override
    public List<Map<String, Object>> inventoryOutList(Integer start, Integer size, String goodsBarCode, String spuNumber, 
                                                      String startTime, String endTime, String userId) {
        return inventoryOutMapper.inventoryOutList(start, size, goodsBarCode, spuNumber, startTime, endTime, userId);
    }

    @Override
    public Integer inventoryOutListAmount(String goodsBarCode, String spuNumber, String startTime, 
                                          String endTime, String userId) {
        return inventoryOutMapper.inventoryOutListAmount(goodsBarCode, spuNumber, startTime, endTime, userId);
    }

    @Override
    public List<Map<String, Object>> inventoryInList(Integer start, Integer size, String goodsBarCode, String spuNumber, 
                                                     String startTime, String endTime, String userId) {
        return inventoryInMapper.inventoryInList(start, size, goodsBarCode, spuNumber, startTime, endTime, userId);
    }

    @Override
    public Integer inventoryInListAmount(String goodsBarCode, String spuNumber, String startTime, String endTime, 
                                         String userId) {
        return inventoryInMapper.inventoryInListMapper(goodsBarCode, spuNumber, startTime, endTime, userId);
    }

    @Override
    public InventoryOutDetail getInventoryOutDetail(String purchaseNumber, String userId,String productId) {
        return inventoryOutDetailMapper.getInventoryOutDetail(purchaseNumber, userId,productId);
    }

    @Override
    public List<Map<String, Object>> getAllInventoryOutDetail(String purchaseNumber, Integer userId, Integer productId) {
        return inventoryOutDetailMapper.getAllInventoryOutDetail(purchaseNumber,userId,productId);
    }

    @Override
    public InventoryInDetail getInventoryOutDetailByisPrice(String purchaseNumber) {
        return inventoryOutMapper.getInventoryOutDetailByisPrice(purchaseNumber);
    }

    @Override
    public int saveInventoryDetail(InventoryDetail inventoryDetail) {
        return inventoryDetailMapper.insert(inventoryDetail);
    }

    @Override
    public int saveInventory(Inventory inventory) {
        return inventoryMapper.insert(inventory);
    }

    @Override
    public List<Map<String, Object>> getUserGoodsBar(Integer productId, String userId) {
        return inventoryDetailMapper.getUserGoodsBar(productId, userId);
    }

    @Override
    public List<Map<String, Object>> getSaleNumberWeek(String userId) {
        return inventoryOutMapper.getSaleNumberWeek(userId);
    }

    @Override
    public PurchaseDetail getPurchaseDetail(@NotNull(message = "产品id不能为空") Integer productId) {
        return inventoryOutMapper.getPurchaseDetail(productId);
    }

    @Override
    public InventoryInDetail getInventoryOutDetailByisDamage(String inOrderNumber) {
        return inventoryOutMapper.getInventoryOutDetailByisDamage(inOrderNumber);
    }

    @Override
    public int getSaleNumber(String userId) {
        return inventoryOutMapper.getSaleNumber(userId);
    }


}
